<template>

    <div class="hc-deliver-header"
         :style="{ background: ($route.meta.headBg ? $route.meta.headBg : ''), position:$route.name==='select-subject' ? 'relative':'fixed'}">
        <div class="hc-deliver-header__wrap" v-if="$route.name!=='landing-page'&&$route.name!=='login'">
            <div class="hc-deliver-header__back"
                 @click="$route.params.back?$router.push($route.params.back):$router.go(-1)"
                 v-if="$route.name !== 'select-subject'">
                <i class="iconfont icon-fanhui1"></i>
                <span class="hc-deliver-header__text">返回</span>
            </div>
            <el-popover placement="bottom" trigger="click" popper-class="el-dropdown-menu">
                <li tabindex="-1" class="el-dropdown-menu__item">
                    班级信息
                </li>
                <li tabindex="-1" @click="logout" class="el-dropdown-menu__item">
                    切换账号
                </li>
                <div class="hc-deliver-header-nav" slot="reference">
                    <span>{{$store.state.Member.class.info.name?$store.state.Member.class.info.name:''}}</span>
                    <i class="el-icon-arrow-down hc-deliver-header-nav__down-icon"></i>
                </div>
            </el-popover>
        </div>
        <div class="hc-deliver-header__subject-icon-list">
            <i class="iconfont icon-menu" v-if="false"></i>
            <i class="iconfont icon-zuixiaohua" @click="toggleWindowAction('min')"></i>
            <i class="iconfont icon-guanbi1" @click="toggleWindowAction('close')"></i>
        </div>
    </div>
</template>

<script>
    // import {CookieUtil} from "../../utils.js/CookieUtil";
    import {mutations_const, actions_const} from '../../config/StoreConstant'
    import {ConstJsonManager} from '../../utils/ConstJsonManager'
    import {clearQuestionCache} from "../../utils/QuestionInfoCache";

    const remote = require('electron').remote;
    export default {
        data() {
            return {
                name: '',
                time: new Date()

            }
        },
        computed: {},
        watch: {},
        methods: {
            toggleWindowAction(type) {
                switch (type) {
                    case 'min' :
                        remote.getCurrentWindow().minimize();
                        break;
                    case 'close' :
                        remote.getCurrentWindow().hide();
                        break;
                }
            },
            logout() {
                clearQuestionCache();
                try {

                    this.$store.commit(mutations_const.UPDATE_HAS_LOGIN, false);
                    this.$store.commit(mutations_const.RESET_LOGIN_MEMBER, {});
                    this.$store.commit(mutations_const.RESET_CLASS, {
                        info: {},
                        member: {},
                        teachingAssistant: {},
                        device: {
                            groupList: [],
                            list: []
                        },
                    });
                    window.ws.send(JSON.stringify({cmd: 0x60}))
                } catch (e) {
                    console.log(e)
                }
                Promise.all([
                    ConstJsonManager.set('token', ''),
                    ConstJsonManager.set('password', ''),
                    // ConstJsonManager.set('autoLogin', false)
                    ConstJsonManager.set('rememberPass', false)
                ])
                    .then(() => {
                        this.$router.push('/login')
                    })
            }
        },
        created() {
            // console.log(remote.process)
        }
    }
</script>
